home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
mac
/
LOGIC Apple II 5.25" Library - ProDOS
/
PRO035.dsk
/
CALC.DOC.2.txt
< prev
next >
Wrap
Text File
|
2012-02-16
|
22KB
|
607 lines
USER DEFINABLE FUNCTIONS
There are 9 user definable functions given by key Y followed by 1-9.
These are defined by writing short program segments and using the
editor command ">" followed by 1-9. This places the current program in
the user function area. User functions can also be downloaded to the
program area for listing by using the editor command "<" 1-9. The user
command will not be permanent, however, unless you type the command to
save the current user commands (U) from the help menu. The user
commands and key redefinitions (see that section) are contained in a
disk file named USERFUNC which is loaded upon initial entry to the
calculator. If this file is not on the disk, then all user functions
will be disregarded and all keys will be interpreted in the standard
manner.
User functions can use all the registers, but when performed, will
not change any registers except the X register. (The registers are
saved and restored.) There is an auto-enter after a user function.
The calculator comes with the user functions defined as follows:
Y1: Multiplication by SQR(-1). (Complex mode only)
Y2: Negate both real & imaginary parts.
Y3-Y7: Get primitive N-th root of 1, N=3-7 (Gets error in real mode)
Y8: 10 to power X.
Y9: LOG(X) to base 10 (common log).
There is also a provision for calling up to 9 separate user supplied
machine language routines. These are accessed by key ^@ followed by
1-9. The addresses of the routines must be placed in a table of
addresses located at $4218-$4229. On entry to the routine, the X
register is placed in the floating point accumulator and upon return
the floating point accumulator is placed in the X register. Routines
must save and restore any zero page locations used. You can access the
registers X, Y, Z, T, 1,..., 9 directly if desired. These are at
$422C-$426C (5 bytes each). Imaginary parts are $80 above these.
(Note that all are on the $42 page.) There is a reserved area of
memory for machine language user routines. A pointer to this area is
found at $422A (just beyond the nine user addresses). Your routines
may use memory from the address in $422A,B to $90FF. The memory area
from $1000 to $1FFF is unlikely to conflict with the calculator and
would also be an appropriate place for user routines.
User machine language routine #9 is now defined to be RANDOM.
It acts on the X register just as the Applesoft command RND(X) works.
This just calls the Applesoft RND routine and affects only the real
part of the X register.
PRINTER INTERFACE
The printer interface refers to a provision for sending the X
register to a printer and has nothing to do with printing of program
listings, which has already been discussed.
The BASIC boot program CALCULATOR will have to be slightly modified
for use with most printers and interface cards. See the section about
configuration. The question asked by this program about printer output
refers to this interface, not to program listings. If it is answered
NO then programs using the interface will run correctly, but, of course,
will not send anything to the printer. If it is answered YES then such
programs can send output to the printer. In this case, if the printer
is not turned on, the program will hang.
For a program to print the X register, the ^N command should be put
in the program at the appropriate place. To instruct a carriage return
to be sent to the printer, | should be used. (Note that ^N never does
a carriage return, so the | must be used if a carriage return is
desired.)
In addition, output can be tabbed, just before printing, by the
^T command followed by 1-9. The tab will be the specified number
times 8.
Output can be formatted by using the ^F command. This must be
followed by a format string containing dashes "-" representing digit
or space positions, possibly a decimal point ".", and possibly commas.
There should be no more than 9 dashes; more will defeat the format
command as will a format command not followed by a legal format string.
The format string will be used for all output by the program until
another format statement occurs. Numbers that are too large for the
allotted space will be printed in their usual Applesoft format.
COPYRIGHT NOTICE
This program is copyrighted 1986 by Glen E. Bredon. All rights
are reserved. If you want to keep this program, please remember to
pay for it by sending your $20 to:
Glen E. Bredon
521 State Road
Princeton, NJ 08540
KEY REDEFINITION
All keys used for calculator commands can be redefined by the user.
This does not apply to help menu or edit commands. The key redefinition
is provided mainly so that newer apples with better keyboards can use
the up and down arrows for the rotation up and down commands, etc.
Otherwise you should be careful about this provision. The redefinition
will have no affect on the text shown on the screen. This could be
changed by careful use of a disk zap program.
Key redefinition is accessed through the editor and is completely
self prompting. Redefined keys are shown and may be reset by defining
each key to mean itself. Redefinitions are not made permanent unless
you use the help menu command U to save user defined functions, since
the key definitions are kept in the same file with those.
Presently the keys ; and = are defined to be * and + so that these
need not be shifted. The up/down arrows are also defined to give the
U and D stack manipulations. All lower case characters are defined
to be their upper case equivalents.
MEMORY MANIPULATIONS:
There are eight memory manipulation commands, only four of which are
indicated on the screen. These are:
M 1-9 Stores X in memory register indicated
R 1-9 Recalls memory register indicated to X (may do auto enter)
< 1-9 Decreases indicated register by one
> 1-9 Increases indicated register by one
^A 1-9 Adds X register to indicated memory register
^O Stores X in register N (1-8) if register 9 contains N
^I Recalls register N (1-8) to X if register 9 contains N
^B -#+ Rotates memory banks
No commands except ^B affect the memory banks not shown on the
screen. The ^B # option just aborts the ^B command. You should not
use a ^B command in a user function because the registers are saved and
restored when doing a user function and this would just result in one
bank being copied to another.
For examples of the use of the indexed store command, see the two
Fourier coefficient computation programs.
PLOTTING FUNCTIONS
To plot a function on the high resolution screen, you must write a
short program segment that contains the function to be plotted inside
square brackets. For example the key sequence ^P [ RTN * ] ^E sets up
a program segment to plot the squaring function. To do the plot, you
then must set X and Y to the left and right boundaries, and Z and T to
the bottom and top boundaries desired and then type ^R to run the
program. Of course, the stack registers may be set up at the start of
the program instead of from the keyboard, if desired.
In complex mode this works somewhat differently. Instead of plotting
the value of the function against the argument, the complex mode plots
the complex value (a point in the plane) of the function for values of
the argument running along the straight line between the points which
are contained in the X and Y registers at the start of the plot command.
Also, the Z register contains the scale factor (usually 1) and the T
register contains the point (complex) to be put at the center of the
screen (usually 0). (Only the real part of the Z register is used.)
Scale 1 will give a distance of 1 from the center of the screen to the
top. Scale .5 gives distance 2, etc.
Complex mode can be used to plot polar equations and more general
parametric functions. See the demonstration programs for several
examples of this.
Key ^Y is the lead in to various "screen functions". Control Y
followed by 1-9 gives:
1. Clear screen at start of plot. *
2. Don't clear screen.
3. Plot axes. *
4. Don't plot axes.
5. Use "dotted" plotting. *
6. Use "solid" plotting.
7. Sound bell and wait for keypress at end of plot. *
8. Do not wait for keypress and do not return to text mode.
9. Set all defaults.
Conditions marked with * are the defaults and all programs start
with these. Function 8 provides a way to "continue" a plot without
user intervention.
In all cases, 279 points are plotted by the plot command, but
multiples of this can be obtained using screen functions 2, 4, and 8
followed by another plot.
Plotting of polar equations is simplified by the function
Exp(i*realpart) given by key "O". Note that this just gives the
complex number cos(t) + i*sin(t) where t is the real part of X.
At the end of a plot, when the bell sounds and a keypress is
expected, if the key you press is the & key then a JSR $3F5 will be
done. This provision can be used to call a routine to dump the high
resolution screen to a printer, either by sending the required command
to a printer interface that has a high resolution dump capability or
by calling a user supplied routine. The best location for such a
routine would be $300-$3CF but longer routines could be placed just
below the high resolution screen.
When doing a plot in step mode the graphics screen is not turned on
until the entire plot is complete. This makes it possible to use the
step provision to debug plotting programs.
A plot saves and replaces all registers, so that the registers will
be the same at the end of the plot as they were at its start.
EXIT TO MONITOR PROVISION
If you type control G you will be sent to the monitor. The floating
point accumulator will contain the unpacked form of register X. You
should return to the calculator with the control Y monitor command.
This provision is made to facilitate testing of floating point routines.
Upon the control Y return the value currently in the floating point
accumulator will be placed in the X register, where it can be examined
by the user. You are free to run any binary program that does not use
any memory above $4200 and does not conflict with the Applesoft zero
page usage. Obviously, some care should be exercised.
This provision can be used to gather the exact floating point number
that you want to use. You should be aware of the fact that prior to the
move to the X register, the floating point accumulator will be rounded
using the high bit of location $AC, so you may want to zero this byte.
This rounding is used by all Applesoft floating point routines.
The Applesoft "floating point accumulator" consists of the memory
locations $9D-$A2. $9D holds the exponent of the number plus $81.
(Thus $80 represents 1/2, $81 represents 1, $82 represents 2, etc., as
a factor the rest of the number must be multiplied by to get the true
value.) The four bytes $9E,$9F,$A0,$A1 contain the normalized number,
which is 1 followed by the part after the "decimal point". Thus the
high bit of $9E is always on and the fractional part begins with the
next highest bit. The byte at $A2 (called FACSGN) holds the sign of
the number. Only the high bit of this location has significance.
When a floating point number is stored to memory it is "packed" by
putting the sign bit (high bit of $A2) into the high bit of $9E.
SUBROUTINES
There is a provision for up to 9 subroutines. The routines must
be placed at the start of the program. (They are not executed
unless called by a GOSUB.)
To define a subroutine while programming, use the K key followed
by specification (1-9) of the subroutine number. (These need not
be in numeric order.) Terminate the subroutine definition with
key B for "return" (or "back").
To call the routine insert a GOSUB in the program with key G,
followed by the number 1-9 of the subroutine to be called.
Subroutines may be nested to a depth of 32. More than this
gives an OUT OF MEMORY error message. Calling a nonexistent
subroutine yields an UNDEF'D STATEMENT error.
SOLVING EQUATIONS
There is a built in facility for solving equations, or, more
precisely, finding zeros of a function. This is done from a program
by key Z. This modifies a PLOT segment (function in square brackets)
into a segment containing a function to be solved for a zero. This
is done by an iterative procedure and the initial quess should be in
the X register when entering the solve mode. For example, to find a
value of x for which COS(x)=x, (converted to finding a zero of the
function COS(x)-x), enter the program ^P Z [ RETURN C - ] ^E. In the
editor this reads:
SOLVE
PLOT
ENTER
COS
Y-X
ENDPLOT
Then enter a quess into the X register and run the program with ^R.
This facility also operates in complex mode. Note that the
iterative procedure may not converge and may yield errors (OVERFLOW,
DIVISION BY ZERO, etc.). Convergence may depend on reasonable guesses
for the first try. This is particularly true of the complex mode.
Two SOLVE instructions in a row (Z key twice) will result in the
Calculator searching for all zeros in the range between the X and Y
registers. On completion, the number of zeros found is in the Z
register and the zeros are in the memory registers (perhaps including
the other banks). This works only in real mode. Note that all
memory registers are set to zero upon the second SOLVE command,
but they may be set up prior to the "[" start of the function and
may be used in the function itself.
SUPPLIED PROGRAMS - DESCRIPTION OF OPERATION
1. QUADRATIC
Purpose: Solves ax^2 + bx + c = 0.
Input a,b,c
On exit: Roots in X, Y
2. AVERAGE
Purpose: Computes average of list of numbers.
Input data, end with ->
On exit: Average in X and in 3, Sum in 1, #entries in 2.
3. FACTORIAL
Purpose: Computes N!.
Input N
On exit: N! in X, N in 1.
4. BINOMIAL
Purpose: Computes binomial coefficient (N:K).
Input N,K
On exit: N in Z, K in Y, (N:K) in X.
5. CASH REG
Purpose: Simulation of cash register.
Input data (dollars and cents but with no decimal point)
While running: Total is in 1, #items in 2, last item in 9
(Item printed if printer selected on boot)
End input with ->
On exit: Z: total
Y: 5% tax
X: Grand total
(These printed if printer selected.)
6. POLAR
Purpose: Converts cartesian to polar coordinates.
Input x,y
On exit: T: r
Z: theta
Y: y
X: x
7. VARIANCE
Purpose: Computes average, variance, standard deviation of data.
Input data x..., end with ->
While running: 1: Sum, 2: Sum of squares, 3: #entries, Y: last entry
On exit: 1: Average
2: Variance
3: Standard deviation
X: # of entries
8. PAUSE
Purpose: Produces 1 second pause. (For use in other programs.)
9. ROUND
Purpose: Rounds X register to 4 decimal places.
10. CORRELATION
Purpose: Computes correlation coefficient of input data.
Input x,y..... pairs, -> to end
On exit: 1: sum of xy
2: sum of x squared
3: sum of y squared
X: correlation coefficient
11. LINEAR REGRESSION
Purpose: Computes line of regression.
Input x,y..... pairs, -> to end
On exit: Z: coef of regression
Y: average of y's
X: average of x's
1: # of pairs x,y
2: sum of x's
3: sum of y's
4: sum of x squared
5: sum of y squared
6: sum of xy
7: covariance
8: variance of x's
9: standard deviation of x's
Regression line is (y-Y)=C(x-X) where C = coef. of regression
12. CHI SQUARE
Purpose: Compute chi square of data.
Input O,E...., end with ->
On exit: X: chi square [sum of {(O-E)^2}/E]
9: #entries
13. DETERMINANT
Purpose: Compute determinant of 3x3 matrix.
Input matrix entries in reading order
On exit: 1-9: matrix entries
X: determinant
14. STIRLING
Purpose: Computes Stirling's appoximation to log n! (base 10).
Input n
On exit: approximation in X.
15. ERROR
Purpose: Computes the error integral from -X to X:
Input X [1/SQR(2pi) times integral of ]
On exit: 1: X [ exp(-x*x/2) dx ]
X: Error integral
16. ELLIPTIC
Purpose: Computes the complete elliptic integrals:
K = integral 0 to pi/2 of (1 - k^2 sin^2 x)^(-1/2) dx
E = integral 0 to pi/2 of (1 - k^2 sin^2 x)^(1/2) dx
Input k
On exit: 1: k
Y: E
X: K
17. RESIDUE
Purpose: Computes residue at 0 of 1/x.
On exit: Y: residue imag. part
X: residue real part
To use for arbitrary function delete line 17 and insert function
18. CUBIC
Purpose: Computes roots of cubic polynomial: ax^3+bx^2+cx+d
Input coefficients a, b, c, d
On exit: 1: a
2: b
3: c
4: d
X, Y, Z: roots (complex)
19. AREA
Purpose: Computes area of polygon.
Input x,y,... (coordinates of vertices of polygon)
End input with ->
On exit: Area in X
20. GEOM MEAN
Purpose: Computes geometric mean of data.
Input data, end with ->
On exit: geom mean in X, #entries in 1
21. FOURIER EVEN
Purpose: Computes even Fourier coefficients of f(X) = X+ABS(X).
On exit: Register N (1-8) contains N-th coefficient: f(x)cos(Nx)dx
Register X contains 0-th coefficient: f(x)dx
The answers are rounded to four decimal places.
22. FOURIER ODD
Purpose: Computes odd Fourier coefficients of f(X) = X+ABS(X).
On exit: Register N (1-8) contains N-th coefficient: f(x)sin(Nx)dx
To use these with an arbitrary function, replace lines 2-4 with
the desired function.
23. PLOT DEMO
Purpose: Demonstrate plotting of real functions.
Plots 2(X^4-X^2+X/3) and then, without erasing, sin(2pi X).
After keypress, plots SQR(ABS(X)), then X*X, then ABS(X)
24. PLOT DEMO 2
Purpose: Demonstrate polar plotting (using complex mode).
Plots the cardioid r=1-cos(th) by plotting the complex function
(1-cos(X))EXP(iX) for X between 0 and 2pi.
After keypress, plots (in "solid" mode) the spiral r=theta by
means of the complex function X*EXP(iX).
25. PLOT DEMO 3
Purpose: Demonstrate error handling for plots.
Plots the function 1/X.
After keypress, plots 1/(X*X-4).
After keypress, plots LOG(X).
26. PLOT INTEGRAL
Purpose: Demonstrate use of integral with a plot.
Plots values of E-1 where E is the complete elliptic integral
(see above) against the parameter k running from 0 to 1. The
vertical axis extends from 0 to .6. This program takes about
50 minutes to run since it computes 279 definite integrals of
a complicated function.
27. LISSAJOUS
Purpose: Demonstrate parametric plotting with Lissajous curves.
Plots these Lissajous curves:
x = sin(3t), y = sin(4t)
x = sin(3t), y = cos(5t)
x = sin(7t), y = cos(11t)
x = sin(13t), y = cos(17t)
(The last one is done in two parts so that 2*279 points are
plotted instead of the usual 279. The program indicates how
this can be done using a loop.)
SUMMARY OF AVAILABLE FUNCTIONS AND COMMANDS
FUNCTION KEYS:
+ Plus
- Minus
* Times
/ Divide
S Sin
C Cos
T Tan
HS Sinh
HC Cosh
HT Tanh
AS Arcsin
AC Arccos
AT Arctan
AHS Argsinh
AHC Argcosh
AHT Argtanh
Q Square root
E Exp
L Log
& Absolute value
N Negate X (In complex mode only the "part" showing.)
! Reciprocal
I Integer part
P Pi
" Real part
' Imaginary part
V Angle (theta in complex mode)
O Exp(i*realpart) (cos(t) + i sin(t))
Y 1-9 User function
^@ 1-9 User machine language routine
MEMORY AND STACK MANIPULATION KEYS:
RETURN Enter
^X Clear X register
^C Clear all registers
D Rotate stack down
U Rotate stack up
X Exchange X and Y
R 1-9 Recall memory to X
M 1-9 Store X in memory
< 1-9 Decrement memory
> 1-9 Increment memory
^A 1-9 Add X to memory
^I Recall of reg 1-8 pointed to by 9
^O Store in reg 1-8 pointed to by 9
^B -#+ Rotate memory banks
MODE KEYS:
# Standard display
$ Hex display
% Degree/Radian toggle
^Z Complex mode toggle
J Real/Imag display toggle
PRINTER INTERFACE KEYS:
^T 1-9 Tab
^N Print X
| Carriage return
^F Format (followed by format string)
PROGRAMMING KEYS:
^P Start programming
^E End programming or abort running program
^W -#+ While
^L 1-9 Loop
\ -#+ If condition
^V Else
^Q Endif
^R Run program in memory
^S Step program in memory
K 1-9 Subroutine definition start
G 1-9 Gosub
B Return from subroutine
^U Skip past current loop (Right arrow key)
^D Get input from datafile (if one is open)
ESC Input request
( Start of integral
(Two in a row give a PRECISION INTEGRAL, precision in T.)
) End of integral
[ Start of function to be plotted
] End of function to be plotted
^Y 1-9 Screen functions (see PLOTTING)
Z Modifies following PLOT segment to a function to SOLVE
(Two in a row give a SOLVE IN RANGE.)
SPECIAL PURPOSE KEYS:
@ Exp during input request
W The character E in immediate numerical input
_ The character - in immediate numerical input
& Does a JSR $3F5 when pressed at end of plot
^G Go to monitor, return by ^Y
? Go to help menu